package com.coderly.onlinegallerysharingplatform.toolkit;

import com.coderly.onlinegallerysharingplatform.common.convention.errorcode.ErrorCode;
import com.coderly.onlinegallerysharingplatform.common.convention.exception.BizException;

/**
 * 异常抛出工具类
 */
public class ExceptionTrowUtils {

    /**
     * 条件成立抛出异常
     * @param condition 条件
     * @param runtimeException 一异常
     */
    public static void throwIf(boolean condition, RuntimeException runtimeException) {
        if (condition) throw runtimeException;
    }

    /**
     * 条件成立，抛出业务异常
     * @param condition 条件
     * @param responseCode  响应码
     */
    public static void throwIf(boolean condition, ErrorCode responseCode) {
        throwIf(condition, new BizException(responseCode));
    }

    /**
     * 条件成立，抛出业务异常
     * @param condition 条件
     * @param responseCode
     * @param message 详细消息
     */
    public static void throwIf(boolean condition, ErrorCode responseCode, String message) {
        throwIf(condition, new BizException(responseCode, message));
    }


}
